home *** CD-ROM | disk | FTP | other *** search
/ Sound Fx / Sound Fx.iso / Software / UNZIPED / MPW181-5 / _SETUP.1 / sublay2.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-04-19  |  44.2 KB  |  895 lines

  1. /* sublay2.cpp
  2.  
  3.    Layer II subband object implementation */
  4.  
  5. /*
  6.  *  @(#) subband_layer_2.cc 1.8, last edit: 6/15/94 16:51:50
  7.  *  @(#) Copyright (C) 1993, 1994 Tobias Bading (bading@cs.tu-berlin.de)
  8.  *  @(#) Berlin University of Technology
  9.  *
  10.  *  This program is free software; you can redistribute it and/or modify
  11.  *  it under the terms of the GNU General Public License as published by
  12.  *  the Free Software Foundation; either version 2 of the License, or
  13.  *  (at your option) any later version.
  14.  *
  15.  *  This program is distributed in the hope that it will be useful,
  16.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  *  GNU General Public License for more details.
  19.  *
  20.  *  You should have received a copy of the GNU General Public License
  21.  *  along with this program; if not, write to the Free Software
  22.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  */
  24.  
  25. /*
  26.  *  Changes from version 1.1 to 1.2:
  27.  *    - calculation of the 3 samples contained in one groupcode is now done
  28.  *      through lookup tables, no more integer modulo or division required.
  29.  *      table_*_quantizationsteps[] arrays replaced by
  30.  *      table_*_groupingtables[] arrays
  31.  
  32.  *    - scalefactors itself instead of scalefactor indices are stored in
  33.  *      SubbandLayer2... objects
  34.  *    - check for small values in [-1.0E-7, 1.0E-7] removed, because the
  35.  *      test itself was slower than some SynthesisFilter::input_sample() calls
  36.  *    - check for illegal scalefactor index 63 removed
  37.  */
  38.  
  39. #ifdef  __WIN32__
  40. #define STRICT
  41. #include <windows.h>
  42. #endif   // __WIN32__
  43.  
  44. #include "sublay2.h"
  45. #include "scalfact.h"
  46.  
  47. static const real grouping_5bits[27 * 3] =
  48. // this table contains 3 requantized samples for each legal codeword
  49. // when grouped in 5 bits, i.e. 3 quantizationsteps per sample
  50. {
  51.   -2.0/3.0, -2.0/3.0, -2.0/3.0,
  52.          0.0, -2.0/3.0, -2.0/3.0,
  53.     2.0/3.0, -2.0/3.0, -2.0/3.0,
  54.   -2.0/3.0,      0.0, -2.0/3.0,
  55.          0.0,      0.0, -2.0/3.0,
  56.     2.0/3.0,      0.0, -2.0/3.0,
  57.   -2.0/3.0,  2.0/3.0, -2.0/3.0,
  58.          0.0,  2.0/3.0, -2.0/3.0,
  59.     2.0/3.0,  2.0/3.0, -2.0/3.0,
  60.   -2.0/3.0, -2.0/3.0,      0.0,
  61.          0.0, -2.0/3.0,      0.0,
  62.     2.0/3.0, -2.0/3.0,      0.0,
  63.   -2.0/3.0,      0.0,      0.0,
  64.          0.0,      0.0,      0.0,
  65.     2.0/3.0,      0.0,      0.0,
  66.   -2.0/3.0,  2.0/3.0,      0.0,
  67.          0.0,  2.0/3.0,      0.0,
  68.     2.0/3.0,  2.0/3.0,      0.0,
  69.   -2.0/3.0, -2.0/3.0,  2.0/3.0,
  70.        0.0, -2.0/3.0,  2.0/3.0,
  71.     2.0/3.0, -2.0/3.0,  2.0/3.0,
  72.   -2.0/3.0,      0.0,  2.0/3.0,
  73.        0.0,      0.0,  2.0/3.0,
  74.    2.0/3.0,      0.0,  2.0/3.0,
  75.   -2.0/3.0,  2.0/3.0,  2.0/3.0,
  76.          0.0,  2.0/3.0,  2.0/3.0,
  77.    2.0/3.0,  2.0/3.0,  2.0/3.0
  78. };
  79.  
  80. static const real grouping_7bits[125 * 3] =
  81. // this table contains 3 requantized samples for each legal codeword
  82. // when grouped in 7 bits, i.e. 5 quantizationsteps per sample
  83. {
  84.   -0.8, -0.8, -0.8,   -0.4, -0.8, -0.8,    0.0, -0.8, -0.8,    0.4, -0.8, -0.8,    0.8, -0.8, -0.8,
  85.   -0.8, -0.4, -0.8,   -0.4, -0.4, -0.8,    0.0, -0.4, -0.8,    0.4, -0.4, -0.8,    0.8, -0.4, -0.8,
  86.   -0.8,  0.0, -0.8,   -0.4,  0.0, -0.8,    0.0,  0.0, -0.8,    0.4,  0.0, -0.8,    0.8,  0.0, -0.8,
  87.   -0.8,  0.4, -0.8,   -0.4,  0.4, -0.8,    0.0,  0.4, -0.8,    0.4,  0.4, -0.8,    0.8,  0.4, -0.8,
  88.   -0.8,  0.8, -0.8,   -0.4,  0.8, -0.8,    0.0,  0.8, -0.8,    0.4,  0.8, -0.8,    0.8,  0.8, -0.8,
  89.   -0.8, -0.8, -0.4,   -0.4, -0.8, -0.4,    0.0, -0.8, -0.4,    0.4, -0.8, -0.4,    0.8, -0.8, -0.4,
  90.   -0.8, -0.4, -0.4,   -0.4, -0.4, -0.4,    0.0, -0.4, -0.4,    0.4, -0.4, -0.4,    0.8, -0.4, -0.4,
  91.   -0.8,  0.0, -0.4,   -0.4,  0.0, -0.4,    0.0,  0.0, -0.4,    0.4,  0.0, -0.4,    0.8,  0.0, -0.4,
  92.   -0.8,  0.4, -0.4,   -0.4,  0.4, -0.4,    0.0,  0.4, -0.4,    0.4,  0.4, -0.4,    0.8,  0.4, -0.4,
  93.   -0.8,  0.8, -0.4,   -0.4,  0.8, -0.4,    0.0,  0.8, -0.4,    0.4,  0.8, -0.4,    0.8,  0.8, -0.4,
  94.   -0.8, -0.8,  0.0,   -0.4, -0.8,  0.0,    0.0, -0.8,  0.0,    0.4, -0.8,  0.0,    0.8, -0.8,  0.0,
  95.   -0.8, -0.4,  0.0,   -0.4, -0.4,  0.0,    0.0, -0.4,  0.0,    0.4, -0.4,  0.0,    0.8, -0.4,  0.0,
  96.   -0.8,  0.0,  0.0,   -0.4,  0.0,  0.0,    0.0,  0.0,  0.0,    0.4,  0.0,  0.0,    0.8,  0.0,  0.0,
  97.   -0.8,  0.4,  0.0,   -0.4,  0.4,  0.0,    0.0,  0.4,  0.0,    0.4,  0.4,  0.0,    0.8,  0.4,  0.0,
  98.   -0.8,  0.8,  0.0,   -0.4,  0.8,  0.0,    0.0,  0.8,  0.0,    0.4,  0.8,  0.0,    0.8,  0.8,  0.0,
  99.   -0.8, -0.8,  0.4,   -0.4, -0.8,  0.4,    0.0, -0.8,  0.4,    0.4, -0.8,  0.4,    0.8, -0.8,  0.4,
  100.   -0.8, -0.4,  0.4,   -0.4, -0.4,  0.4,    0.0, -0.4,  0.4,    0.4, -0.4,  0.4,    0.8, -0.4,  0.4,
  101.   -0.8,  0.0,  0.4,   -0.4,  0.0,  0.4,    0.0,  0.0,  0.4,    0.4,  0.0,  0.4,    0.8,  0.0,  0.4,
  102.   -0.8,  0.4,  0.4,   -0.4,  0.4,  0.4,    0.0,  0.4,  0.4,    0.4,  0.4,  0.4,    0.8,  0.4,  0.4,
  103.   -0.8,  0.8,  0.4,   -0.4,  0.8,  0.4,    0.0,  0.8,  0.4,    0.4,  0.8,  0.4,    0.8,  0.8,  0.4,
  104.   -0.8, -0.8,  0.8,   -0.4, -0.8,  0.8,    0.0, -0.8,  0.8,    0.4, -0.8,  0.8,    0.8, -0.8,  0.8,
  105.   -0.8, -0.4,  0.8,   -0.4, -0.4,  0.8,    0.0, -0.4,  0.8,    0.4, -0.4,  0.8,    0.8, -0.4,  0.8,
  106.   -0.8,  0.0,  0.8,   -0.4,  0.0,  0.8,    0.0,  0.0,  0.8,    0.4,  0.0,  0.8,    0.8,  0.0,  0.8,
  107.   -0.8,  0.4,  0.8,   -0.4,  0.4,  0.8,    0.0,  0.4,  0.8,    0.4,  0.4,  0.8,    0.8,  0.4,  0.8,
  108.   -0.8,  0.8,  0.8,   -0.4,  0.8,  0.8,    0.0,  0.8,  0.8,    0.4,  0.8,  0.8,    0.8,  0.8,  0.8
  109. };
  110.  
  111. static const real grouping_10bits[729 * 3] =
  112. // this table contains 3 requantized samples for each legal codeword
  113. // when grouped in 10 bits, i.e. 9 quantizationsteps per sample
  114. {
  115.   -8.0/9.0, -8.0/9.0, -8.0/9.0,   -6.0/9.0, -8.0/9.0, -8.0/9.0,   -4.0/9.0, -8.0/9.0, -8.0/9.0,
  116.   -2.0/9.0, -8.0/9.0, -8.0/9.0,        0.0, -8.0/9.0, -8.0/9.0,    2.0/9.0, -8.0/9.0, -8.0/9.0,
  117.     4.0/9.0, -8.0/9.0, -8.0/9.0,    6.0/9.0, -8.0/9.0, -8.0/9.0,    8.0/9.0, -8.0/9.0, -8.0/9.0,
  118.   -8.0/9.0, -6.0/9.0, -8.0/9.0,   -6.0/9.0, -6.0/9.0, -8.0/9.0,   -4.0/9.0, -6.0/9.0, -8.0/9.0,
  119.   -2.0/9.0, -6.0/9.0, -8.0/9.0,        0.0, -6.0/9.0, -8.0/9.0,    2.0/9.0, -6.0/9.0, -8.0/9.0,
  120.     4.0/9.0, -6.0/9.0, -8.0/9.0,    6.0/9.0, -6.0/9.0, -8.0/9.0,    8.0/9.0, -6.0/9.0, -8.0/9.0,
  121.   -8.0/9.0, -4.0/9.0, -8.0/9.0,   -6.0/9.0, -4.0/9.0, -8.0/9.0,   -4.0/9.0, -4.0/9.0, -8.0/9.0,
  122.   -2.0/9.0, -4.0/9.0, -8.0/9.0,        0.0, -4.0/9.0, -8.0/9.0,    2.0/9.0, -4.0/9.0, -8.0/9.0,
  123.     4.0/9.0, -4.0/9.0, -8.0/9.0,    6.0/9.0, -4.0/9.0, -8.0/9.0,    8.0/9.0, -4.0/9.0, -8.0/9.0,
  124.   -8.0/9.0, -2.0/9.0, -8.0/9.0,   -6.0/9.0, -2.0/9.0, -8.0/9.0,   -4.0/9.0, -2.0/9.0, -8.0/9.0,
  125.   -2.0/9.0, -2.0/9.0, -8.0/9.0,        0.0, -2.0/9.0, -8.0/9.0,    2.0/9.0, -2.0/9.0, -8.0/9.0,
  126.     4.0/9.0, -2.0/9.0, -8.0/9.0,    6.0/9.0, -2.0/9.0, -8.0/9.0,    8.0/9.0, -2.0/9.0, -8.0/9.0,
  127.   -8.0/9.0,      0.0, -8.0/9.0,   -6.0/9.0,      0.0, -8.0/9.0,   -4.0/9.0,      0.0, -8.0/9.0,
  128.   -2.0/9.0,      0.0, -8.0/9.0,        0.0,      0.0, -8.0/9.0,    2.0/9.0,      0.0, -8.0/9.0,
  129.     4.0/9.0,      0.0, -8.0/9.0,    6.0/9.0,      0.0, -8.0/9.0,    8.0/9.0,      0.0, -8.0/9.0,
  130.   -8.0/9.0,  2.0/9.0, -8.0/9.0,   -6.0/9.0,  2.0/9.0, -8.0/9.0,   -4.0/9.0,  2.0/9.0, -8.0/9.0,
  131.   -2.0/9.0,  2.0/9.0, -8.0/9.0,        0.0,  2.0/9.0, -8.0/9.0,    2.0/9.0,  2.0/9.0, -8.0/9.0,
  132.     4.0/9.0,  2.0/9.0, -8.0/9.0,    6.0/9.0,  2.0/9.0, -8.0/9.0,    8.0/9.0,  2.0/9.0, -8.0/9.0,
  133.   -8.0/9.0,  4.0/9.0, -8.0/9.0,   -6.0/9.0,  4.0/9.0, -8.0/9.0,   -4.0/9.0,  4.0/9.0, -8.0/9.0,
  134.   -2.0/9.0,  4.0/9.0, -8.0/9.0,        0.0,  4.0/9.0, -8.0/9.0,    2.0/9.0,  4.0/9.0, -8.0/9.0,
  135.     4.0/9.0,  4.0/9.0, -8.0/9.0,    6.0/9.0,  4.0/9.0, -8.0/9.0,    8.0/9.0,  4.0/9.0, -8.0/9.0,
  136.   -8.0/9.0,  6.0/9.0, -8.0/9.0,   -6.0/9.0,  6.0/9.0, -8.0/9.0,   -4.0/9.0,  6.0/9.0, -8.0/9.0,
  137.   -2.0/9.0,  6.0/9.0, -8.0/9.0,        0.0,  6.0/9.0, -8.0/9.0,    2.0/9.0,  6.0/9.0, -8.0/9.0,
  138.     4.0/9.0,  6.0/9.0, -8.0/9.0,    6.0/9.0,  6.0/9.0, -8.0/9.0,    8.0/9.0,  6.0/9.0, -8.0/9.0,
  139.   -8.0/9.0,  8.0/9.0, -8.0/9.0,   -6.0/9.0,  8.0/9.0, -8.0/9.0,   -4.0/9.0,  8.0/9.0, -8.0/9.0,
  140.   -2.0/9.0,  8.0/9.0, -8.0/9.0,        0.0,  8.0/9.0, -8.0/9.0,    2.0/9.0,  8.0/9.0, -8.0/9.0,
  141.     4.0/9.0,  8.0/9.0, -8.0/9.0,    6.0/9.0,  8.0/9.0, -8.0/9.0,    8.0/9.0,  8.0/9.0, -8.0/9.0,
  142.   -8.0/9.0, -8.0/9.0, -6.0/9.0,   -6.0/9.0, -8.0/9.0, -6.0/9.0,   -4.0/9.0, -8.0/9.0, -6.0/9.0,
  143.   -2.0/9.0, -8.0/9.0, -6.0/9.0,        0.0, -8.0/9.0, -6.0/9.0,    2.0/9.0, -8.0/9.0, -6.0/9.0,
  144.     4.0/9.0, -8.0/9.0, -6.0/9.0,    6.0/9.0, -8.0/9.0, -6.0/9.0,    8.0/9.0, -8.0/9.0, -6.0/9.0,
  145.   -8.0/9.0, -6.0/9.0, -6.0/9.0,   -6.0/9.0, -6.0/9.0, -6.0/9.0,   -4.0/9.0, -6.0/9.0, -6.0/9.0,
  146.   -2.0/9.0, -6.0/9.0, -6.0/9.0,        0.0, -6.0/9.0, -6.0/9.0,    2.0/9.0, -6.0/9.0, -6.0/9.0,
  147.     4.0/9.0, -6.0/9.0, -6.0/9.0,    6.0/9.0, -6.0/9.0, -6.0/9.0,    8.0/9.0, -6.0/9.0, -6.0/9.0,
  148.   -8.0/9.0, -4.0/9.0, -6.0/9.0,   -6.0/9.0, -4.0/9.0, -6.0/9.0,   -4.0/9.0, -4.0/9.0, -6.0/9.0,
  149.   -2.0/9.0, -4.0/9.0, -6.0/9.0,        0.0, -4.0/9.0, -6.0/9.0,    2.0/9.0, -4.0/9.0, -6.0/9.0,
  150.     4.0/9.0, -4.0/9.0, -6.0/9.0,    6.0/9.0, -4.0/9.0, -6.0/9.0,    8.0/9.0, -4.0/9.0, -6.0/9.0,
  151.   -8.0/9.0, -2.0/9.0, -6.0/9.0,   -6.0/9.0, -2.0/9.0, -6.0/9.0,   -4.0/9.0, -2.0/9.0, -6.0/9.0,
  152.   -2.0/9.0, -2.0/9.0, -6.0/9.0,        0.0, -2.0/9.0, -6.0/9.0,    2.0/9.0, -2.0/9.0, -6.0/9.0,
  153.     4.0/9.0, -2.0/9.0, -6.0/9.0,    6.0/9.0, -2.0/9.0, -6.0/9.0,    8.0/9.0, -2.0/9.0, -6.0/9.0,
  154.   -8.0/9.0,      0.0, -6.0/9.0,   -6.0/9.0,      0.0, -6.0/9.0,   -4.0/9.0,      0.0, -6.0/9.0,
  155.   -2.0/9.0,      0.0, -6.0/9.0,        0.0,      0.0, -6.0/9.0,    2.0/9.0,      0.0, -6.0/9.0,
  156.     4.0/9.0,      0.0, -6.0/9.0,    6.0/9.0,      0.0, -6.0/9.0,    8.0/9.0,      0.0, -6.0/9.0,
  157.   -8.0/9.0,  2.0/9.0, -6.0/9.0,   -6.0/9.0,  2.0/9.0, -6.0/9.0,   -4.0/9.0,  2.0/9.0, -6.0/9.0,
  158.   -2.0/9.0,  2.0/9.0, -6.0/9.0,        0.0,  2.0/9.0, -6.0/9.0,    2.0/9.0,  2.0/9.0, -6.0/9.0,
  159.     4.0/9.0,  2.0/9.0, -6.0/9.0,    6.0/9.0,  2.0/9.0, -6.0/9.0,    8.0/9.0,  2.0/9.0, -6.0/9.0,
  160.   -8.0/9.0,  4.0/9.0, -6.0/9.0,   -6.0/9.0,  4.0/9.0, -6.0/9.0,   -4.0/9.0,  4.0/9.0, -6.0/9.0,
  161.   -2.0/9.0,  4.0/9.0, -6.0/9.0,        0.0,  4.0/9.0, -6.0/9.0,    2.0/9.0,  4.0/9.0, -6.0/9.0,
  162.     4.0/9.0,  4.0/9.0, -6.0/9.0,    6.0/9.0,  4.0/9.0, -6.0/9.0,    8.0/9.0,  4.0/9.0, -6.0/9.0,
  163.   -8.0/9.0,  6.0/9.0, -6.0/9.0,   -6.0/9.0,  6.0/9.0, -6.0/9.0,   -4.0/9.0,  6.0/9.0, -6.0/9.0,
  164.   -2.0/9.0,  6.0/9.0, -6.0/9.0,        0.0,  6.0/9.0, -6.0/9.0,    2.0/9.0,  6.0/9.0, -6.0/9.0,
  165.     4.0/9.0,  6.0/9.0, -6.0/9.0,    6.0/9.0,  6.0/9.0, -6.0/9.0,    8.0/9.0,  6.0/9.0, -6.0/9.0,
  166.   -8.0/9.0,  8.0/9.0, -6.0/9.0,   -6.0/9.0,  8.0/9.0, -6.0/9.0,   -4.0/9.0,  8.0/9.0, -6.0/9.0,
  167.   -2.0/9.0,  8.0/9.0, -6.0/9.0,        0.0,  8.0/9.0, -6.0/9.0,    2.0/9.0,  8.0/9.0, -6.0/9.0,
  168.     4.0/9.0,  8.0/9.0, -6.0/9.0,    6.0/9.0,  8.0/9.0, -6.0/9.0,    8.0/9.0,  8.0/9.0, -6.0/9.0,
  169.   -8.0/9.0, -8.0/9.0, -4.0/9.0,   -6.0/9.0, -8.0/9.0, -4.0/9.0,   -4.0/9.0, -8.0/9.0, -4.0/9.0,
  170.   -2.0/9.0, -8.0/9.0, -4.0/9.0,        0.0, -8.0/9.0, -4.0/9.0,    2.0/9.0, -8.0/9.0, -4.0/9.0,
  171.     4.0/9.0, -8.0/9.0, -4.0/9.0,    6.0/9.0, -8.0/9.0, -4.0/9.0,    8.0/9.0, -8.0/9.0, -4.0/9.0,
  172.   -8.0/9.0, -6.0/9.0, -4.0/9.0,   -6.0/9.0, -6.0/9.0, -4.0/9.0,   -4.0/9.0, -6.0/9.0, -4.0/9.0,
  173.   -2.0/9.0, -6.0/9.0, -4.0/9.0,        0.0, -6.0/9.0, -4.0/9.0,    2.0/9.0, -6.0/9.0, -4.0/9.0,
  174.     4.0/9.0, -6.0/9.0, -4.0/9.0,    6.0/9.0, -6.0/9.0, -4.0/9.0,    8.0/9.0, -6.0/9.0, -4.0/9.0,
  175.   -8.0/9.0, -4.0/9.0, -4.0/9.0,   -6.0/9.0, -4.0/9.0, -4.0/9.0,   -4.0/9.0, -4.0/9.0, -4.0/9.0,
  176.   -2.0/9.0, -4.0/9.0, -4.0/9.0,        0.0, -4.0/9.0, -4.0/9.0,    2.0/9.0, -4.0/9.0, -4.0/9.0,
  177.     4.0/9.0, -4.0/9.0, -4.0/9.0,    6.0/9.0, -4.0/9.0, -4.0/9.0,    8.0/9.0, -4.0/9.0, -4.0/9.0,
  178.   -8.0/9.0, -2.0/9.0, -4.0/9.0,   -6.0/9.0, -2.0/9.0, -4.0/9.0,   -4.0/9.0, -2.0/9.0, -4.0/9.0,
  179.   -2.0/9.0, -2.0/9.0, -4.0/9.0,        0.0, -2.0/9.0, -4.0/9.0,    2.0/9.0, -2.0/9.0, -4.0/9.0,
  180.     4.0/9.0, -2.0/9.0, -4.0/9.0,    6.0/9.0, -2.0/9.0, -4.0/9.0,    8.0/9.0, -2.0/9.0, -4.0/9.0,
  181.   -8.0/9.0,      0.0, -4.0/9.0,   -6.0/9.0,      0.0, -4.0/9.0,   -4.0/9.0,      0.0, -4.0/9.0,
  182.   -2.0/9.0,      0.0, -4.0/9.0,        0.0,      0.0, -4.0/9.0,    2.0/9.0,      0.0, -4.0/9.0,
  183.     4.0/9.0,      0.0, -4.0/9.0,    6.0/9.0,      0.0, -4.0/9.0,    8.0/9.0,      0.0, -4.0/9.0,
  184.   -8.0/9.0,  2.0/9.0, -4.0/9.0,   -6.0/9.0,  2.0/9.0, -4.0/9.0,   -4.0/9.0,  2.0/9.0, -4.0/9.0,
  185.   -2.0/9.0,  2.0/9.0, -4.0/9.0,        0.0,  2.0/9.0, -4.0/9.0,    2.0/9.0,  2.0/9.0, -4.0/9.0,
  186.     4.0/9.0,  2.0/9.0, -4.0/9.0,    6.0/9.0,  2.0/9.0, -4.0/9.0,    8.0/9.0,  2.0/9.0, -4.0/9.0,
  187.   -8.0/9.0,  4.0/9.0, -4.0/9.0,   -6.0/9.0,  4.0/9.0, -4.0/9.0,   -4.0/9.0,  4.0/9.0, -4.0/9.0,
  188.   -2.0/9.0,  4.0/9.0, -4.0/9.0,        0.0,  4.0/9.0, -4.0/9.0,    2.0/9.0,  4.0/9.0, -4.0/9.0,
  189.     4.0/9.0,  4.0/9.0, -4.0/9.0,    6.0/9.0,  4.0/9.0, -4.0/9.0,    8.0/9.0,  4.0/9.0, -4.0/9.0,
  190.   -8.0/9.0,  6.0/9.0, -4.0/9.0,   -6.0/9.0,  6.0/9.0, -4.0/9.0,   -4.0/9.0,  6.0/9.0, -4.0/9.0,
  191.   -2.0/9.0,  6.0/9.0, -4.0/9.0,        0.0,  6.0/9.0, -4.0/9.0,    2.0/9.0,  6.0/9.0, -4.0/9.0,
  192.     4.0/9.0,  6.0/9.0, -4.0/9.0,    6.0/9.0,  6.0/9.0, -4.0/9.0,    8.0/9.0,  6.0/9.0, -4.0/9.0,
  193.   -8.0/9.0,  8.0/9.0, -4.0/9.0,   -6.0/9.0,  8.0/9.0, -4.0/9.0,   -4.0/9.0,  8.0/9.0, -4.0/9.0,
  194.   -2.0/9.0,  8.0/9.0, -4.0/9.0,        0.0,  8.0/9.0, -4.0/9.0,    2.0/9.0,  8.0/9.0, -4.0/9.0,
  195.     4.0/9.0,  8.0/9.0, -4.0/9.0,    6.0/9.0,  8.0/9.0, -4.0/9.0,    8.0/9.0,  8.0/9.0, -4.0/9.0,
  196.   -8.0/9.0, -8.0/9.0, -2.0/9.0,   -6.0/9.0, -8.0/9.0, -2.0/9.0,   -4.0/9.0, -8.0/9.0, -2.0/9.0,
  197.   -2.0/9.0, -8.0/9.0, -2.0/9.0,        0.0, -8.0/9.0, -2.0/9.0,    2.0/9.0, -8.0/9.0, -2.0/9.0,
  198.     4.0/9.0, -8.0/9.0, -2.0/9.0,    6.0/9.0, -8.0/9.0, -2.0/9.0,    8.0/9.0, -8.0/9.0, -2.0/9.0,
  199.   -8.0/9.0, -6.0/9.0, -2.0/9.0,   -6.0/9.0, -6.0/9.0, -2.0/9.0,   -4.0/9.0, -6.0/9.0, -2.0/9.0,
  200.   -2.0/9.0, -6.0/9.0, -2.0/9.0,        0.0, -6.0/9.0, -2.0/9.0,    2.0/9.0, -6.0/9.0, -2.0/9.0,
  201.     4.0/9.0, -6.0/9.0, -2.0/9.0,    6.0/9.0, -6.0/9.0, -2.0/9.0,    8.0/9.0, -6.0/9.0, -2.0/9.0,
  202.   -8.0/9.0, -4.0/9.0, -2.0/9.0,   -6.0/9.0, -4.0/9.0, -2.0/9.0,   -4.0/9.0, -4.0/9.0, -2.0/9.0,
  203.   -2.0/9.0, -4.0/9.0, -2.0/9.0,        0.0, -4.0/9.0, -2.0/9.0,    2.0/9.0, -4.0/9.0, -2.0/9.0,
  204.     4.0/9.0, -4.0/9.0, -2.0/9.0,    6.0/9.0, -4.0/9.0, -2.0/9.0,    8.0/9.0, -4.0/9.0, -2.0/9.0,
  205.   -8.0/9.0, -2.0/9.0, -2.0/9.0,   -6.0/9.0, -2.0/9.0, -2.0/9.0,   -4.0/9.0, -2.0/9.0, -2.0/9.0,
  206.   -2.0/9.0, -2.0/9.0, -2.0/9.0,        0.0, -2.0/9.0, -2.0/9.0,    2.0/9.0, -2.0/9.0, -2.0/9.0,
  207.     4.0/9.0, -2.0/9.0, -2.0/9.0,    6.0/9.0, -2.0/9.0, -2.0/9.0,    8.0/9.0, -2.0/9.0, -2.0/9.0,
  208.   -8.0/9.0,      0.0, -2.0/9.0,   -6.0/9.0,      0.0, -2.0/9.0,   -4.0/9.0,      0.0, -2.0/9.0,
  209.   -2.0/9.0,      0.0, -2.0/9.0,        0.0,      0.0, -2.0/9.0,    2.0/9.0,      0.0, -2.0/9.0,
  210.     4.0/9.0,      0.0, -2.0/9.0,    6.0/9.0,      0.0, -2.0/9.0,    8.0/9.0,      0.0, -2.0/9.0,
  211.   -8.0/9.0,  2.0/9.0, -2.0/9.0,   -6.0/9.0,  2.0/9.0, -2.0/9.0,   -4.0/9.0,  2.0/9.0, -2.0/9.0,
  212.   -2.0/9.0,  2.0/9.0, -2.0/9.0,        0.0,  2.0/9.0, -2.0/9.0,    2.0/9.0,  2.0/9.0, -2.0/9.0,
  213.     4.0/9.0,  2.0/9.0, -2.0/9.0,    6.0/9.0,  2.0/9.0, -2.0/9.0,    8.0/9.0,  2.0/9.0, -2.0/9.0,
  214.   -8.0/9.0,  4.0/9.0, -2.0/9.0,   -6.0/9.0,  4.0/9.0, -2.0/9.0,   -4.0/9.0,  4.0/9.0, -2.0/9.0,
  215.   -2.0/9.0,  4.0/9.0, -2.0/9.0,        0.0,  4.0/9.0, -2.0/9.0,    2.0/9.0,  4.0/9.0, -2.0/9.0,
  216.     4.0/9.0,  4.0/9.0, -2.0/9.0,    6.0/9.0,  4.0/9.0, -2.0/9.0,    8.0/9.0,  4.0/9.0, -2.0/9.0,
  217.   -8.0/9.0,  6.0/9.0, -2.0/9.0,   -6.0/9.0,  6.0/9.0, -2.0/9.0,   -4.0/9.0,  6.0/9.0, -2.0/9.0,
  218.   -2.0/9.0,  6.0/9.0, -2.0/9.0,        0.0,  6.0/9.0, -2.0/9.0,    2.0/9.0,  6.0/9.0, -2.0/9.0,
  219.     4.0/9.0,  6.0/9.0, -2.0/9.0,    6.0/9.0,  6.0/9.0, -2.0/9.0,    8.0/9.0,  6.0/9.0, -2.0/9.0,
  220.   -8.0/9.0,  8.0/9.0, -2.0/9.0,   -6.0/9.0,  8.0/9.0, -2.0/9.0,   -4.0/9.0,  8.0/9.0, -2.0/9.0,
  221.   -2.0/9.0,  8.0/9.0, -2.0/9.0,        0.0,  8.0/9.0, -2.0/9.0,    2.0/9.0,  8.0/9.0, -2.0/9.0,
  222.     4.0/9.0,  8.0/9.0, -2.0/9.0,    6.0/9.0,  8.0/9.0, -2.0/9.0,    8.0/9.0,  8.0/9.0, -2.0/9.0,
  223.   -8.0/9.0, -8.0/9.0,      0.0,   -6.0/9.0, -8.0/9.0,      0.0,   -4.0/9.0, -8.0/9.0,      0.0,
  224.   -2.0/9.0, -8.0/9.0,      0.0,        0.0, -8.0/9.0,      0.0,    2.0/9.0, -8.0/9.0,      0.0,
  225.     4.0/9.0, -8.0/9.0,      0.0,    6.0/9.0, -8.0/9.0,      0.0,    8.0/9.0, -8.0/9.0,      0.0,
  226.   -8.0/9.0, -6.0/9.0,      0.0,   -6.0/9.0, -6.0/9.0,      0.0,   -4.0/9.0, -6.0/9.0,      0.0,
  227.   -2.0/9.0, -6.0/9.0,      0.0,        0.0, -6.0/9.0,      0.0,    2.0/9.0, -6.0/9.0,      0.0,
  228.     4.0/9.0, -6.0/9.0,      0.0,    6.0/9.0, -6.0/9.0,      0.0,    8.0/9.0, -6.0/9.0,      0.0,
  229.   -8.0/9.0, -4.0/9.0,      0.0,   -6.0/9.0, -4.0/9.0,      0.0,   -4.0/9.0, -4.0/9.0,      0.0,
  230.   -2.0/9.0, -4.0/9.0,      0.0,        0.0, -4.0/9.0,      0.0,    2.0/9.0, -4.0/9.0,      0.0,
  231.     4.0/9.0, -4.0/9.0,      0.0,    6.0/9.0, -4.0/9.0,      0.0,    8.0/9.0, -4.0/9.0,      0.0,
  232.   -8.0/9.0, -2.0/9.0,      0.0,   -6.0/9.0, -2.0/9.0,      0.0,   -4.0/9.0, -2.0/9.0,      0.0,
  233.   -2.0/9.0, -2.0/9.0,      0.0,        0.0, -2.0/9.0,      0.0,    2.0/9.0, -2.0/9.0,      0.0,
  234.     4.0/9.0, -2.0/9.0,      0.0,    6.0/9.0, -2.0/9.0,      0.0,    8.0/9.0, -2.0/9.0,      0.0,
  235.   -8.0/9.0,      0.0,      0.0,   -6.0/9.0,      0.0,      0.0,   -4.0/9.0,      0.0,      0.0,
  236.   -2.0/9.0,      0.0,      0.0,        0.0,      0.0,      0.0,    2.0/9.0,      0.0,      0.0,
  237.     4.0/9.0,      0.0,      0.0,    6.0/9.0,      0.0,      0.0,    8.0/9.0,      0.0,      0.0,
  238.   -8.0/9.0,  2.0/9.0,      0.0,   -6.0/9.0,  2.0/9.0,      0.0,   -4.0/9.0,  2.0/9.0,      0.0,
  239.   -2.0/9.0,  2.0/9.0,      0.0,        0.0,  2.0/9.0,      0.0,    2.0/9.0,  2.0/9.0,      0.0,
  240.     4.0/9.0,  2.0/9.0,      0.0,    6.0/9.0,  2.0/9.0,      0.0,    8.0/9.0,  2.0/9.0,      0.0,
  241.   -8.0/9.0,  4.0/9.0,      0.0,   -6.0/9.0,  4.0/9.0,      0.0,   -4.0/9.0,  4.0/9.0,      0.0,
  242.   -2.0/9.0,  4.0/9.0,      0.0,        0.0,  4.0/9.0,      0.0,    2.0/9.0,  4.0/9.0,      0.0,
  243.     4.0/9.0,  4.0/9.0,      0.0,    6.0/9.0,  4.0/9.0,      0.0,    8.0/9.0,  4.0/9.0,      0.0,
  244.   -8.0/9.0,  6.0/9.0,      0.0,   -6.0/9.0,  6.0/9.0,      0.0,   -4.0/9.0,  6.0/9.0,      0.0,
  245.   -2.0/9.0,  6.0/9.0,      0.0,        0.0,  6.0/9.0,      0.0,    2.0/9.0,  6.0/9.0,      0.0,
  246.     4.0/9.0,  6.0/9.0,      0.0,    6.0/9.0,  6.0/9.0,      0.0,    8.0/9.0,  6.0/9.0,      0.0,
  247.   -8.0/9.0,  8.0/9.0,      0.0,   -6.0/9.0,  8.0/9.0,      0.0,   -4.0/9.0,  8.0/9.0,      0.0,
  248.   -2.0/9.0,  8.0/9.0,      0.0,        0.0,  8.0/9.0,      0.0,    2.0/9.0,  8.0/9.0,      0.0,
  249.    4.0/9.0,  8.0/9.0,      0.0,    6.0/9.0,  8.0/9.0,      0.0,    8.0/9.0,  8.0/9.0,      0.0,
  250.   -8.0/9.0, -8.0/9.0,  2.0/9.0,   -6.0/9.0, -8.0/9.0,  2.0/9.0,   -4.0/9.0, -8.0/9.0,  2.0/9.0,
  251.   -2.0/9.0, -8.0/9.0,  2.0/9.0,        0.0, -8.0/9.0,  2.0/9.0,    2.0/9.0, -8.0/9.0,  2.0/9.0,
  252.     4.0/9.0, -8.0/9.0,  2.0/9.0,    6.0/9.0, -8.0/9.0,  2.0/9.0,    8.0/9.0, -8.0/9.0,  2.0/9.0,
  253.   -8.0/9.0, -6.0/9.0,  2.0/9.0,   -6.0/9.0, -6.0/9.0,  2.0/9.0,   -4.0/9.0, -6.0/9.0,  2.0/9.0,
  254.   -2.0/9.0, -6.0/9.0,  2.0/9.0,        0.0, -6.0/9.0,  2.0/9.0,    2.0/9.0, -6.0/9.0,  2.0/9.0,
  255.     4.0/9.0, -6.0/9.0,  2.0/9.0,    6.0/9.0, -6.0/9.0,  2.0/9.0,    8.0/9.0, -6.0/9.0,  2.0/9.0,
  256.   -8.0/9.0, -4.0/9.0,  2.0/9.0,   -6.0/9.0, -4.0/9.0,  2.0/9.0,   -4.0/9.0, -4.0/9.0,  2.0/9.0,
  257.   -2.0/9.0, -4.0/9.0,  2.0/9.0,        0.0, -4.0/9.0,  2.0/9.0,    2.0/9.0, -4.0/9.0,  2.0/9.0,
  258.    4.0/9.0, -4.0/9.0,  2.0/9.0,    6.0/9.0, -4.0/9.0,  2.0/9.0,    8.0/9.0, -4.0/9.0,  2.0/9.0,
  259.   -8.0/9.0, -2.0/9.0,  2.0/9.0,   -6.0/9.0, -2.0/9.0,  2.0/9.0,   -4.0/9.0, -2.0/9.0,  2.0/9.0,
  260.   -2.0/9.0, -2.0/9.0,  2.0/9.0,        0.0, -2.0/9.0,  2.0/9.0,    2.0/9.0, -2.0/9.0,  2.0/9.0,
  261.    4.0/9.0, -2.0/9.0,  2.0/9.0,    6.0/9.0, -2.0/9.0,  2.0/9.0,    8.0/9.0, -2.0/9.0,  2.0/9.0,
  262.   -8.0/9.0,      0.0,  2.0/9.0,   -6.0/9.0,      0.0,  2.0/9.0,   -4.0/9.0,      0.0,  2.0/9.0,
  263.   -2.0/9.0,      0.0,  2.0/9.0,        0.0,      0.0,  2.0/9.0,    2.0/9.0,      0.0,  2.0/9.0,
  264.    4.0/9.0,      0.0,  2.0/9.0,    6.0/9.0,      0.0,  2.0/9.0,    8.0/9.0,      0.0,  2.0/9.0,
  265.   -8.0/9.0,  2.0/9.0,  2.0/9.0,   -6.0/9.0,  2.0/9.0,  2.0/9.0,   -4.0/9.0,  2.0/9.0,  2.0/9.0,
  266.   -2.0/9.0,  2.0/9.0,  2.0/9.0,        0.0,  2.0/9.0,  2.0/9.0,    2.0/9.0,  2.0/9.0,  2.0/9.0,
  267.    4.0/9.0,  2.0/9.0,  2.0/9.0,    6.0/9.0,  2.0/9.0,  2.0/9.0,    8.0/9.0,  2.0/9.0,  2.0/9.0,
  268.   -8.0/9.0,  4.0/9.0,  2.0/9.0,   -6.0/9.0,  4.0/9.0,  2.0/9.0,   -4.0/9.0,  4.0/9.0,  2.0/9.0,
  269.   -2.0/9.0,  4.0/9.0,  2.0/9.0,        0.0,  4.0/9.0,  2.0/9.0,    2.0/9.0,  4.0/9.0,  2.0/9.0,
  270.     4.0/9.0,  4.0/9.0,  2.0/9.0,    6.0/9.0,  4.0/9.0,  2.0/9.0,    8.0/9.0,  4.0/9.0,  2.0/9.0,
  271.   -8.0/9.0,  6.0/9.0,  2.0/9.0,   -6.0/9.0,  6.0/9.0,  2.0/9.0,   -4.0/9.0,  6.0/9.0,  2.0/9.0,
  272.   -2.0/9.0,  6.0/9.0,  2.0/9.0,        0.0,  6.0/9.0,  2.0/9.0,    2.0/9.0,  6.0/9.0,  2.0/9.0,
  273.    4.0/9.0,  6.0/9.0,  2.0/9.0,    6.0/9.0,  6.0/9.0,  2.0/9.0,    8.0/9.0,  6.0/9.0,  2.0/9.0,
  274.   -8.0/9.0,  8.0/9.0,  2.0/9.0,   -6.0/9.0,  8.0/9.0,  2.0/9.0,   -4.0/9.0,  8.0/9.0,  2.0/9.0,
  275.   -2.0/9.0,  8.0/9.0,  2.0/9.0,        0.0,  8.0/9.0,  2.0/9.0,    2.0/9.0,  8.0/9.0,  2.0/9.0,
  276.    4.0/9.0,  8.0/9.0,  2.0/9.0,    6.0/9.0,  8.0/9.0,  2.0/9.0,    8.0/9.0,  8.0/9.0,  2.0/9.0,
  277.   -8.0/9.0, -8.0/9.0,  4.0/9.0,   -6.0/9.0, -8.0/9.0,  4.0/9.0,   -4.0/9.0, -8.0/9.0,  4.0/9.0,
  278.   -2.0/9.0, -8.0/9.0,  4.0/9.0,        0.0, -8.0/9.0,  4.0/9.0,    2.0/9.0, -8.0/9.0,  4.0/9.0,
  279.     4.0/9.0, -8.0/9.0,  4.0/9.0,    6.0/9.0, -8.0/9.0,  4.0/9.0,    8.0/9.0, -8.0/9.0,  4.0/9.0,
  280.   -8.0/9.0, -6.0/9.0,  4.0/9.0,   -6.0/9.0, -6.0/9.0,  4.0/9.0,   -4.0/9.0, -6.0/9.0,  4.0/9.0,
  281.   -2.0/9.0, -6.0/9.0,  4.0/9.0,        0.0, -6.0/9.0,  4.0/9.0,    2.0/9.0, -6.0/9.0,  4.0/9.0,
  282.    4.0/9.0, -6.0/9.0,  4.0/9.0,    6.0/9.0, -6.0/9.0,  4.0/9.0,    8.0/9.0, -6.0/9.0,  4.0/9.0,
  283.   -8.0/9.0, -4.0/9.0,  4.0/9.0,   -6.0/9.0, -4.0/9.0,  4.0/9.0,   -4.0/9.0, -4.0/9.0,  4.0/9.0,
  284.   -2.0/9.0, -4.0/9.0,  4.0/9.0,        0.0, -4.0/9.0,  4.0/9.0,    2.0/9.0, -4.0/9.0,  4.0/9.0,
  285.    4.0/9.0, -4.0/9.0,  4.0/9.0,    6.0/9.0, -4.0/9.0,  4.0/9.0,    8.0/9.0, -4.0/9.0,  4.0/9.0,
  286.   -8.0/9.0, -2.0/9.0,  4.0/9.0,   -6.0/9.0, -2.0/9.0,  4.0/9.0,   -4.0/9.0, -2.0/9.0,  4.0/9.0,
  287.   -2.0/9.0, -2.0/9.0,  4.0/9.0,        0.0, -2.0/9.0,  4.0/9.0,    2.0/9.0, -2.0/9.0,  4.0/9.0,
  288.     4.0/9.0, -2.0/9.0,  4.0/9.0,    6.0/9.0, -2.0/9.0,  4.0/9.0,    8.0/9.0, -2.0/9.0,  4.0/9.0,
  289.   -8.0/9.0,      0.0,  4.0/9.0,   -6.0/9.0,      0.0,  4.0/9.0,   -4.0/9.0,      0.0,  4.0/9.0,
  290.   -2.0/9.0,      0.0,  4.0/9.0,        0.0,      0.0,  4.0/9.0,    2.0/9.0,      0.0,  4.0/9.0,
  291.    4.0/9.0,      0.0,  4.0/9.0,    6.0/9.0,      0.0,  4.0/9.0,    8.0/9.0,      0.0,  4.0/9.0,
  292.   -8.0/9.0,  2.0/9.0,  4.0/9.0,   -6.0/9.0,  2.0/9.0,  4.0/9.0,   -4.0/9.0,  2.0/9.0,  4.0/9.0,
  293.   -2.0/9.0,  2.0/9.0,  4.0/9.0,        0.0,  2.0/9.0,  4.0/9.0,    2.0/9.0,  2.0/9.0,  4.0/9.0,
  294.    4.0/9.0,  2.0/9.0,  4.0/9.0,    6.0/9.0,  2.0/9.0,  4.0/9.0,    8.0/9.0,  2.0/9.0,  4.0/9.0,
  295.   -8.0/9.0,  4.0/9.0,  4.0/9.0,   -6.0/9.0,  4.0/9.0,  4.0/9.0,   -4.0/9.0,  4.0/9.0,  4.0/9.0,
  296.   -2.0/9.0,  4.0/9.0,  4.0/9.0,        0.0,  4.0/9.0,  4.0/9.0,    2.0/9.0,  4.0/9.0,  4.0/9.0,
  297.    4.0/9.0,  4.0/9.0,  4.0/9.0,    6.0/9.0,  4.0/9.0,  4.0/9.0,    8.0/9.0,  4.0/9.0,  4.0/9.0,
  298.   -8.0/9.0,  6.0/9.0,  4.0/9.0,   -6.0/9.0,  6.0/9.0,  4.0/9.0,   -4.0/9.0,  6.0/9.0,  4.0/9.0,
  299.   -2.0/9.0,  6.0/9.0,  4.0/9.0,        0.0,  6.0/9.0,  4.0/9.0,    2.0/9.0,  6.0/9.0,  4.0/9.0,
  300.     4.0/9.0,  6.0/9.0,  4.0/9.0,    6.0/9.0,  6.0/9.0,  4.0/9.0,    8.0/9.0,  6.0/9.0,  4.0/9.0,
  301.   -8.0/9.0,  8.0/9.0,  4.0/9.0,   -6.0/9.0,  8.0/9.0,  4.0/9.0,   -4.0/9.0,  8.0/9.0,  4.0/9.0,
  302.   -2.0/9.0,  8.0/9.0,  4.0/9.0,        0.0,  8.0/9.0,  4.0/9.0,    2.0/9.0,  8.0/9.0,  4.0/9.0,
  303.     4.0/9.0,  8.0/9.0,  4.0/9.0,    6.0/9.0,  8.0/9.0,  4.0/9.0,    8.0/9.0,  8.0/9.0,  4.0/9.0,
  304.   -8.0/9.0, -8.0/9.0,  6.0/9.0,   -6.0/9.0, -8.0/9.0,  6.0/9.0,   -4.0/9.0, -8.0/9.0,  6.0/9.0,
  305.   -2.0/9.0, -8.0/9.0,  6.0/9.0,        0.0, -8.0/9.0,  6.0/9.0,    2.0/9.0, -8.0/9.0,  6.0/9.0,
  306.    4.0/9.0, -8.0/9.0,  6.0/9.0,    6.0/9.0, -8.0/9.0,  6.0/9.0,    8.0/9.0, -8.0/9.0,  6.0/9.0,
  307.   -8.0/9.0, -6.0/9.0,  6.0/9.0,   -6.0/9.0, -6.0/9.0,  6.0/9.0,   -4.0/9.0, -6.0/9.0,  6.0/9.0,
  308.   -2.0/9.0, -6.0/9.0,  6.0/9.0,        0.0, -6.0/9.0,  6.0/9.0,    2.0/9.0, -6.0/9.0,  6.0/9.0,
  309.    4.0/9.0, -6.0/9.0,  6.0/9.0,    6.0/9.0, -6.0/9.0,  6.0/9.0,    8.0/9.0, -6.0/9.0,  6.0/9.0,
  310.   -8.0/9.0, -4.0/9.0,  6.0/9.0,   -6.0/9.0, -4.0/9.0,  6.0/9.0,   -4.0/9.0, -4.0/9.0,  6.0/9.0,
  311.   -2.0/9.0, -4.0/9.0,  6.0/9.0,        0.0, -4.0/9.0,  6.0/9.0,    2.0/9.0, -4.0/9.0,  6.0/9.0,
  312.     4.0/9.0, -4.0/9.0,  6.0/9.0,    6.0/9.0, -4.0/9.0,  6.0/9.0,    8.0/9.0, -4.0/9.0,  6.0/9.0,
  313.   -8.0/9.0, -2.0/9.0,  6.0/9.0,   -6.0/9.0, -2.0/9.0,  6.0/9.0,   -4.0/9.0, -2.0/9.0,  6.0/9.0,
  314.   -2.0/9.0, -2.0/9.0,  6.0/9.0,        0.0, -2.0/9.0,  6.0/9.0,    2.0/9.0, -2.0/9.0,  6.0/9.0,
  315.    4.0/9.0, -2.0/9.0,  6.0/9.0,    6.0/9.0, -2.0/9.0,  6.0/9.0,    8.0/9.0, -2.0/9.0,  6.0/9.0,
  316.   -8.0/9.0,      0.0,  6.0/9.0,   -6.0/9.0,      0.0,  6.0/9.0,   -4.0/9.0,      0.0,  6.0/9.0,
  317.   -2.0/9.0,      0.0,  6.0/9.0,        0.0,      0.0,  6.0/9.0,    2.0/9.0,      0.0,  6.0/9.0,
  318.     4.0/9.0,      0.0,  6.0/9.0,    6.0/9.0,      0.0,  6.0/9.0,    8.0/9.0,      0.0,  6.0/9.0,
  319.   -8.0/9.0,  2.0/9.0,  6.0/9.0,   -6.0/9.0,  2.0/9.0,  6.0/9.0,   -4.0/9.0,  2.0/9.0,  6.0/9.0,
  320.   -2.0/9.0,  2.0/9.0,  6.0/9.0,        0.0,  2.0/9.0,  6.0/9.0,    2.0/9.0,  2.0/9.0,  6.0/9.0,
  321.     4.0/9.0,  2.0/9.0,  6.0/9.0,    6.0/9.0,  2.0/9.0,  6.0/9.0,    8.0/9.0,  2.0/9.0,  6.0/9.0,
  322.   -8.0/9.0,  4.0/9.0,  6.0/9.0,   -6.0/9.0,  4.0/9.0,  6.0/9.0,   -4.0/9.0,  4.0/9.0,  6.0/9.0,
  323.   -2.0/9.0,  4.0/9.0,  6.0/9.0,        0.0,  4.0/9.0,  6.0/9.0,    2.0/9.0,  4.0/9.0,  6.0/9.0,
  324.     4.0/9.0,  4.0/9.0,  6.0/9.0,    6.0/9.0,  4.0/9.0,  6.0/9.0,    8.0/9.0,  4.0/9.0,  6.0/9.0,
  325.   -8.0/9.0,  6.0/9.0,  6.0/9.0,   -6.0/9.0,  6.0/9.0,  6.0/9.0,   -4.0/9.0,  6.0/9.0,  6.0/9.0,
  326.   -2.0/9.0,  6.0/9.0,  6.0/9.0,        0.0,  6.0/9.0,  6.0/9.0,    2.0/9.0,  6.0/9.0,  6.0/9.0,
  327.     4.0/9.0,  6.0/9.0,  6.0/9.0,    6.0/9.0,  6.0/9.0,  6.0/9.0,    8.0/9.0,  6.0/9.0,  6.0/9.0,
  328.   -8.0/9.0,  8.0/9.0,  6.0/9.0,   -6.0/9.0,  8.0/9.0,  6.0/9.0,   -4.0/9.0,  8.0/9.0,  6.0/9.0,
  329.   -2.0/9.0,  8.0/9.0,  6.0/9.0,        0.0,  8.0/9.0,  6.0/9.0,    2.0/9.0,  8.0/9.0,  6.0/9.0,
  330.     4.0/9.0,  8.0/9.0,  6.0/9.0,    6.0/9.0,  8.0/9.0,  6.0/9.0,    8.0/9.0,  8.0/9.0,  6.0/9.0,
  331.   -8.0/9.0, -8.0/9.0,  8.0/9.0,   -6.0/9.0, -8.0/9.0,  8.0/9.0,   -4.0/9.0, -8.0/9.0,  8.0/9.0,
  332.   -2.0/9.0, -8.0/9.0,  8.0/9.0,        0.0, -8.0/9.0,  8.0/9.0,    2.0/9.0, -8.0/9.0,  8.0/9.0,
  333.    4.0/9.0, -8.0/9.0,  8.0/9.0,    6.0/9.0, -8.0/9.0,  8.0/9.0,    8.0/9.0, -8.0/9.0,  8.0/9.0,
  334.   -8.0/9.0, -6.0/9.0,  8.0/9.0,   -6.0/9.0, -6.0/9.0,  8.0/9.0,   -4.0/9.0, -6.0/9.0,  8.0/9.0,
  335.   -2.0/9.0, -6.0/9.0,  8.0/9.0,        0.0, -6.0/9.0,  8.0/9.0,    2.0/9.0, -6.0/9.0,  8.0/9.0,
  336.     4.0/9.0, -6.0/9.0,  8.0/9.0,    6.0/9.0, -6.0/9.0,  8.0/9.0,    8.0/9.0, -6.0/9.0,  8.0/9.0,
  337.   -8.0/9.0, -4.0/9.0,  8.0/9.0,   -6.0/9.0, -4.0/9.0,  8.0/9.0,   -4.0/9.0, -4.0/9.0,  8.0/9.0,
  338.   -2.0/9.0, -4.0/9.0,  8.0/9.0,        0.0, -4.0/9.0,  8.0/9.0,    2.0/9.0, -4.0/9.0,  8.0/9.0,
  339.    4.0/9.0, -4.0/9.0,  8.0/9.0,    6.0/9.0, -4.0/9.0,  8.0/9.0,    8.0/9.0, -4.0/9.0,  8.0/9.0,
  340.   -8.0/9.0, -2.0/9.0,  8.0/9.0,   -6.0/9.0, -2.0/9.0,  8.0/9.0,   -4.0/9.0, -2.0/9.0,  8.0/9.0,
  341.   -2.0/9.0, -2.0/9.0,  8.0/9.0,        0.0, -2.0/9.0,  8.0/9.0,    2.0/9.0, -2.0/9.0,  8.0/9.0,
  342.    4.0/9.0, -2.0/9.0,  8.0/9.0,    6.0/9.0, -2.0/9.0,  8.0/9.0,    8.0/9.0, -2.0/9.0,  8.0/9.0,
  343.   -8.0/9.0,      0.0,  8.0/9.0,   -6.0/9.0,      0.0,  8.0/9.0,   -4.0/9.0,      0.0,  8.0/9.0,
  344.   -2.0/9.0,      0.0,  8.0/9.0,        0.0,      0.0,  8.0/9.0,    2.0/9.0,      0.0,  8.0/9.0,
  345.    4.0/9.0,      0.0,  8.0/9.0,    6.0/9.0,      0.0,  8.0/9.0,    8.0/9.0,      0.0,  8.0/9.0,
  346.   -8.0/9.0,  2.0/9.0,  8.0/9.0,   -6.0/9.0,  2.0/9.0,  8.0/9.0,   -4.0/9.0,  2.0/9.0,  8.0/9.0,
  347.   -2.0/9.0,  2.0/9.0,  8.0/9.0,        0.0,  2.0/9.0,  8.0/9.0,    2.0/9.0,  2.0/9.0,  8.0/9.0,
  348.     4.0/9.0,  2.0/9.0,  8.0/9.0,    6.0/9.0,  2.0/9.0,  8.0/9.0,    8.0/9.0,  2.0/9.0,  8.0/9.0,
  349.   -8.0/9.0,  4.0/9.0,  8.0/9.0,   -6.0/9.0,  4.0/9.0,  8.0/9.0,   -4.0/9.0,  4.0/9.0,  8.0/9.0,
  350.   -2.0/9.0,  4.0/9.0,  8.0/9.0,        0.0,  4.0/9.0,  8.0/9.0,    2.0/9.0,  4.0/9.0,  8.0/9.0,
  351.     4.0/9.0,  4.0/9.0,  8.0/9.0,    6.0/9.0,  4.0/9.0,  8.0/9.0,    8.0/9.0,  4.0/9.0,  8.0/9.0,
  352.   -8.0/9.0,  6.0/9.0,  8.0/9.0,   -6.0/9.0,  6.0/9.0,  8.0/9.0,   -4.0/9.0,  6.0/9.0,  8.0/9.0,
  353.   -2.0/9.0,  6.0/9.0,  8.0/9.0,        0.0,  6.0/9.0,  8.0/9.0,    2.0/9.0,  6.0/9.0,  8.0/9.0,
  354.    4.0/9.0,  6.0/9.0,  8.0/9.0,    6.0/9.0,  6.0/9.0,  8.0/9.0,    8.0/9.0,  6.0/9.0,  8.0/9.0,
  355.   -8.0/9.0,  8.0/9.0,  8.0/9.0,   -6.0/9.0,  8.0/9.0,  8.0/9.0,   -4.0/9.0,  8.0/9.0,  8.0/9.0,
  356.   -2.0/9.0,  8.0/9.0,  8.0/9.0,        0.0,  8.0/9.0,  8.0/9.0,    2.0/9.0,  8.0/9.0,  8.0/9.0,
  357.    4.0/9.0,  8.0/9.0,  8.0/9.0,    6.0/9.0,  8.0/9.0,  8.0/9.0,    8.0/9.0,  8.0/9.0,  8.0/9.0
  358. };
  359.  
  360.  
  361. // data taken from ISO/IEC DIS 11172, Annexes 3-B.2[abcd] and 3-B.4:
  362.  
  363. // subbands 0-2 in tables 3-B.2a and 2b: (index is allocation)
  364. static const uint32 table_ab1_codelength[16] =
  365.   // bits per codeword
  366. { 0, 5, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
  367.  
  368. static const real *table_ab1_groupingtables[16] =
  369.   // pointer to sample grouping table, or NULL-pointer if ungrouped
  370. { 0, grouping_5bits, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  371.  
  372. static const real table_ab1_factor[16] =
  373.   // factor for requantization: (real)sample * factor - 1.0 gives requantized sample
  374. { 0.0, 1.0/2.0, 1.0/4.0, 1.0/8.0, 1.0/16.0, 1.0/32.0, 1.0/64.0,
  375.   1.0/128.0, 1.0/256.0, 1.0/512.0, 1.0/1024.0, 1.0/2048.0,
  376.   1.0/4096.0, 1.0/8192.0, 1.0/16384.0, 1.0/32768.0 };
  377.  
  378. static const real table_ab1_c[16] =
  379.   // factor c for requantization from table 3-B.4
  380. { 0.0,           1.33333333333, 1.14285714286, 1.06666666666, 1.03225806452,
  381.   1.01587301587, 1.00787401575, 1.00392156863, 1.00195694716, 1.00097751711,
  382.   1.00048851979, 1.00024420024, 1.00012208522, 1.00006103888, 1.00003051851,
  383.   1.00001525902 };
  384. static const real table_ab1_d[16] =
  385.   // addend d for requantization from table 3-B.4
  386. { 0.0,           0.50000000000, 0.25000000000, 0.12500000000, 0.06250000000,
  387.   0.03125000000, 0.01562500000, 0.00781250000, 0.00390625000, 0.00195312500,
  388.   0.00097656250, 0.00048828125, 0.00024414063, 0.00012207031, 0.00006103516,
  389.   0.00003051758 };
  390.  
  391. // subbands 3-... tables 3-B.2a and 2b:
  392. static const real *table_ab234_groupingtables[16] =
  393. { 0, grouping_5bits, grouping_7bits, 0, grouping_10bits, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  394.  
  395. // subbands 3-10 in tables 3-B.2a and 2b:
  396. static const uint32 table_ab2_codelength[16] =
  397. { 0, 5, 7, 3, 10, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16 };
  398. static const real table_ab2_factor[16] =
  399. { 0.0, 1.0/2.0, 1.0/4.0, 1.0/4.0, 1.0/8.0, 1.0/8.0, 1.0/16.0,
  400.   1.0/32.0, 1.0/64.0, 1.0/128.0, 1.0/256.0, 1.0/512.0,
  401.   1.0/1024.0, 1.0/2048.0, 1.0/4096.0, 1.0/32768.0 };
  402. static const real table_ab2_c[16] =
  403. { 0.0,           1.33333333333, 1.60000000000, 1.14285714286, 1.77777777777,
  404.   1.06666666666, 1.03225806452, 1.01587301587, 1.00787401575, 1.00392156863,
  405.   1.00195694716, 1.00097751711, 1.00048851979, 1.00024420024, 1.00012208522,
  406.   1.00001525902 };
  407. static const real table_ab2_d[16] =
  408. { 0.0,           0.50000000000, 0.50000000000, 0.25000000000, 0.50000000000,
  409.   0.12500000000, 0.06250000000, 0.03125000000, 0.01562500000, 0.00781250000,
  410.   0.00390625000, 0.00195312500, 0.00097656250, 0.00048828125, 0.00024414063,
  411.   0.00003051758 };
  412.  
  413. // subbands 11-22 in tables 3-B.2a and 2b:
  414. static const uint32 table_ab3_codelength[8] = { 0, 5, 7, 3, 10, 4, 5, 16 };
  415. static const real table_ab3_factor[8] =
  416. { 0.0, 1.0/2.0, 1.0/4.0, 1.0/4.0, 1.0/8.0, 1.0/8.0, 1.0/16.0, 1.0/32768.0 };
  417. static const real table_ab3_c[8] =
  418. { 0.0,           1.33333333333, 1.60000000000, 1.14285714286, 1.77777777777,
  419.   1.06666666666, 1.03225806452, 1.00001525902 };
  420. static const real table_ab3_d[8] =
  421. { 0.0,           0.50000000000, 0.50000000000, 0.25000000000, 0.50000000000,
  422.   0.12500000000, 0.06250000000, 0.00003051758 };
  423.  
  424. // subbands 23-... in tables 3-B.2a and 2b:
  425. static const uint32 table_ab4_codelength[4] = { 0, 5, 7, 16 };
  426. static const real table_ab4_factor[8] = { 0.0, 1.0/2.0, 1.0/4.0, 1.0/32768.0 };
  427. static const real table_ab4_c[4] = { 0.0, 1.33333333333, 1.60000000000, 1.00001525902 };
  428. static const real table_ab4_d[4] = { 0.0, 0.50000000000, 0.50000000000, 0.00003051758 };
  429.  
  430. // subbands in tables 3-B.2c and 2d:
  431. static const uint32 table_cd_codelength[16] =
  432. { 0, 5, 7, 10, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
  433. static const real *table_cd_groupingtables[16] =
  434. { 0, grouping_5bits, grouping_7bits, grouping_10bits, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  435. static const real table_cd_factor[16] =
  436. { 0.0, 1.0/2.0, 1.0/4.0, 1.0/8.0, 1.0/8.0, 1.0/16.0, 1.0/32.0, 1.0/64.0,
  437.   1.0/128.0, 1.0/256.0, 1.0/512.0, 1.0/1024.0, 1.0/2048.0, 1.0/4096.0,
  438.   1.0/8192.0, 1.0/16384.0 };
  439. static const real table_cd_c[16] =
  440. { 0.0,           1.33333333333, 1.60000000000, 1.77777777777, 1.06666666666,
  441.   1.03225806452, 1.01587301587, 1.00787401575, 1.00392156863, 1.00195694716,
  442.   1.00097751711, 1.00048851979, 1.00024420024, 1.00012208522, 1.00006103888,
  443.   1.00003051851 };
  444. static const real table_cd_d[16] =
  445. { 0.0,           0.50000000000, 0.50000000000, 0.50000000000, 0.12500000000,
  446.   0.06250000000, 0.03125000000, 0.01562500000, 0.00781250000, 0.00390625000,
  447.   0.00195312500, 0.00097656250, 0.00048828125, 0.00024414063, 0.00012207031,
  448.   0.00006103516 };
  449.  
  450.  
  451.  
  452. /**********************/    // used for single channel mode
  453. /*** Standard Class ***/    // and in derived class for intensity
  454. /**********************/    // stereo mode
  455.  
  456. SubbandLayer2::SubbandLayer2 (uint32 subbandnumber)
  457. {
  458.   this->subbandnumber = subbandnumber;
  459.   groupnumber = samplenumber = 0;
  460. }
  461.  
  462.  
  463. uint32 SubbandLayer2::get_allocationlength (Header *header)
  464. {
  465.   uint32 channel_bitrate = header->bitrate_index ();
  466.  
  467.   // calculate bitrate per channel:
  468.   if (header->mode () != single_channel)
  469.      if (channel_bitrate == 4)
  470.         channel_bitrate = 1;
  471.      else
  472.         channel_bitrate -= 4;
  473.  
  474.   if (channel_bitrate == 1 || channel_bitrate == 2)
  475.      // table 3-B.2c or 3-B.2d
  476.      if (subbandnumber <= 1)
  477.         return(4);
  478.      else
  479.         return(3);
  480.   else
  481.      // tables 3-B.2a or 3-B.2b
  482.      if (subbandnumber <= 10)
  483.         return(4);
  484.      else if (subbandnumber <= 22)
  485.         return(3);
  486.      else
  487.         return(2);
  488. }
  489.  
  490.  
  491. void SubbandLayer2::prepare_sample_reading (Header *header, uint32 allocation,
  492.     const real **groupingtable, real *factor, uint32 *codelength, real *c, real *d)
  493. {
  494.   uint32 channel_bitrate = header->bitrate_index ();
  495.  
  496.   // calculate bitrate per channel:
  497.   if (header->mode () != single_channel)
  498.      if (channel_bitrate == 4)
  499.         channel_bitrate = 1;
  500.      else
  501.         channel_bitrate -= 4;
  502.  
  503.   if (channel_bitrate == 1 || channel_bitrate == 2)
  504.   {
  505.      // table 3-B.2c or 3-B.2d
  506.      *groupingtable = table_cd_groupingtables[allocation];
  507.      *factor = table_cd_factor[allocation];
  508.      *codelength = table_cd_codelength[allocation];
  509.      *c = table_cd_c[allocation];
  510.      *d = table_cd_d[allocation];
  511.   }
  512.   else
  513.   {
  514.      // tables 3-B.2a or 3-B.2b
  515.      if (subbandnumber <= 2)
  516.      {
  517.         *groupingtable = table_ab1_groupingtables[allocation];
  518.         *factor = table_ab1_factor[allocation];
  519.         *codelength = table_ab1_codelength[allocation];
  520.       *c = table_ab1_c[allocation];
  521.       *d = table_ab1_d[allocation];
  522.     }
  523.      else
  524.      {
  525.       *groupingtable = table_ab234_groupingtables[allocation];
  526.         if (subbandnumber <= 10)
  527.         {
  528.     *factor = table_ab2_factor[allocation];
  529.     *codelength = table_ab2_codelength[allocation];
  530.     *c = table_ab2_c[allocation];
  531.     *d = table_ab2_d[allocation];
  532.       }
  533.       else if (subbandnumber <= 22)
  534.       {
  535.     *factor = table_ab3_factor[allocation];
  536.     *codelength = table_ab3_codelength[allocation];
  537.     *c = table_ab3_c[allocation];
  538.     *d = table_ab3_d[allocation];
  539.       }
  540.         else
  541.       {
  542.     *factor = table_ab4_factor[allocation];
  543.     *codelength = table_ab4_codelength[allocation];
  544.     *c = table_ab4_c[allocation];
  545.     *d = table_ab4_d[allocation];
  546.       }
  547.     }
  548.   }
  549. }
  550.  
  551.  
  552. void SubbandLayer2::read_allocation (Ibitstream *stream, Header *header, Crc16 *crc)
  553. {
  554.   register uint32 length = get_allocationlength (header);
  555.   allocation = stream->get_bits (length);
  556.   if (crc)
  557.     crc->add_bits (allocation, length);
  558. }
  559.  
  560.  
  561. void SubbandLayer2::read_scalefactor_selection (Ibitstream *stream, Crc16 *crc)
  562. {
  563.   if (allocation)
  564.   {
  565.     scfsi = stream->get_bits (2);
  566.     if (crc)
  567.         crc->add_bits (scfsi, 2);
  568.   }
  569. }
  570.  
  571.  
  572. void SubbandLayer2::read_scalefactor (Ibitstream *stream, Header *header)
  573. {
  574.   if (allocation)
  575.   {
  576.     switch (scfsi)
  577.     {
  578.       case 0:
  579.     scalefactor1 = scalefactors[stream->get_bits (6)];
  580.     scalefactor2 = scalefactors[stream->get_bits (6)];
  581.     scalefactor3 = scalefactors[stream->get_bits (6)];
  582.     break;
  583.         case 1:
  584.     scalefactor1 = scalefactor2 = scalefactors[stream->get_bits (6)];
  585.     scalefactor3 = scalefactors[stream->get_bits (6)];
  586.     break;
  587.       case 2:
  588.     scalefactor1 = scalefactor2 = scalefactor3 = scalefactors[stream->get_bits (6)];
  589.     break;
  590.         case 3:
  591.     scalefactor1 = scalefactors[stream->get_bits (6)];
  592.     scalefactor2 = scalefactor3 = scalefactors[stream->get_bits (6)];
  593.     break;
  594.     }
  595.     prepare_sample_reading (header, allocation, &groupingtable,
  596.                 &factor, &codelength, &c, &d);
  597.   }
  598. }
  599.  
  600.  
  601. BOOL SubbandLayer2::read_sampledata (Ibitstream *stream)
  602. {
  603.   if (allocation)
  604.      if (groupingtable)
  605.      {
  606.         uint32 samplecode = stream->get_bits (codelength);
  607.         // create requantized samples:
  608.         samplecode += samplecode << 1;
  609.         register real *target = samples;
  610.         register const real *source = groupingtable + samplecode;
  611.         *target++ = *source++;
  612.         *target++ = *source++;
  613.         *target = *source;
  614.         // memcpy (samples, groupingtable + samplecode, 3 * sizeof (real));
  615.      }
  616.      else
  617.      {
  618.         samples[0] = real (stream->get_bits (codelength)) * factor - 1.0;
  619.         samples[1] = real (stream->get_bits (codelength)) * factor - 1.0;
  620.         samples[2] = real (stream->get_bits (codelength)) * factor - 1.0;
  621.      }
  622.  
  623.   samplenumber = 0;
  624.   if (++groupnumber == 12)
  625.      return(TRUE);
  626.   else
  627.      return(FALSE);
  628. }
  629.  
  630.  
  631. BOOL SubbandLayer2::put_next_sample (e_channels channels,
  632.                       SynthesisFilter *filter1, SynthesisFilter *)
  633. {
  634.   if (allocation && channels != right)
  635.   {
  636.      register real sample = samples[samplenumber];
  637.  
  638.      if (!groupingtable)
  639.         sample = (sample + d) * c;
  640.      if (groupnumber <= 4)
  641.         sample *= scalefactor1;
  642.      else if (groupnumber <= 8)
  643.         sample *= scalefactor2;
  644.      else
  645.         sample *= scalefactor3;
  646.      filter1->input_sample (sample, subbandnumber);
  647.   }
  648.  
  649.   if (++samplenumber == 3)
  650.      return(TRUE);
  651.   else
  652.      return(FALSE);
  653. }
  654.  
  655.  
  656.  
  657. /******************************/
  658. /*** Intensity Stereo Class ***/
  659. /******************************/
  660.  
  661. SubbandLayer2IntensityStereo::SubbandLayer2IntensityStereo (uint32 subbandnumber)
  662. : SubbandLayer2 (subbandnumber)
  663. {
  664. }
  665.  
  666.  
  667. void SubbandLayer2IntensityStereo::read_scalefactor_selection (Ibitstream *stream, Crc16 *crc)
  668. {
  669.   if (allocation)
  670.   {
  671.      scfsi = stream->get_bits (2);
  672.      channel2_scfsi = stream->get_bits (2);
  673.      if (crc)
  674.      {
  675.         crc->add_bits (scfsi, 2);
  676.         crc->add_bits (channel2_scfsi, 2);
  677.      }
  678.   }
  679. }
  680.  
  681.  
  682. void SubbandLayer2IntensityStereo::read_scalefactor (Ibitstream *stream, Header *header)
  683. {
  684.   if (allocation)
  685.   {
  686.      SubbandLayer2::read_scalefactor (stream, header);
  687.      switch (channel2_scfsi)
  688.      {
  689.         case 0:
  690.     channel2_scalefactor1 = scalefactors[stream->get_bits (6)];
  691.     channel2_scalefactor2 = scalefactors[stream->get_bits (6)];
  692.     channel2_scalefactor3 = scalefactors[stream->get_bits (6)];
  693.     break;
  694.         case 1:
  695.     channel2_scalefactor1 = channel2_scalefactor2 = scalefactors[stream->get_bits (6)];
  696.     channel2_scalefactor3 = scalefactors[stream->get_bits (6)];
  697.     break;
  698.         case 2:
  699.     channel2_scalefactor1 = channel2_scalefactor2 =
  700.     channel2_scalefactor3 = scalefactors[stream->get_bits (6)];
  701.     break;
  702.         case 3:
  703.     channel2_scalefactor1 = scalefactors[stream->get_bits (6)];
  704.     channel2_scalefactor2 = channel2_scalefactor3 = scalefactors[stream->get_bits (6)];
  705.     break;
  706.      }
  707.   }
  708. }
  709.  
  710.  
  711. BOOL SubbandLayer2IntensityStereo::put_next_sample (e_channels channels,
  712.     SynthesisFilter *filter1, SynthesisFilter *filter2)
  713. {
  714.   if (allocation)
  715.   {
  716.      register real sample = samples[samplenumber];
  717.  
  718.      if (!groupingtable)
  719.         sample = (sample + d) * c;
  720.     if (channels == both)
  721.     {
  722.         register float sample2 = sample;
  723.       if (groupnumber <= 4)
  724.       {
  725.     sample *= scalefactor1;
  726.     sample2 *= channel2_scalefactor1;
  727.         }
  728.         else if (groupnumber <= 8)
  729.         {
  730.     sample *= scalefactor2;
  731.     sample2 *= channel2_scalefactor2;
  732.         }
  733.         else
  734.         {
  735.     sample *= scalefactor3;
  736.     sample2 *= channel2_scalefactor3;
  737.         }
  738.         filter1->input_sample (sample, subbandnumber);
  739.       filter2->input_sample (sample2, subbandnumber);
  740.     }
  741.     else if (channels == left)
  742.      {
  743.         if (groupnumber <= 4)
  744.     sample *= scalefactor1;
  745.       else if (groupnumber <= 8)
  746.     sample *= scalefactor2;
  747.         else
  748.     sample *= scalefactor3;
  749.         filter1->input_sample (sample, subbandnumber);
  750.      }
  751.      else
  752.      {
  753.         if (groupnumber <= 4)
  754.     sample *= channel2_scalefactor1;
  755.         else if (groupnumber <= 8)
  756.     sample *= channel2_scalefactor2;
  757.         else
  758.     sample *= channel2_scalefactor3;
  759.         filter1->input_sample (sample, subbandnumber);
  760.      }
  761.   }
  762.  
  763.   if (++samplenumber == 3)
  764.      return(TRUE);
  765.   else
  766.      return(FALSE);
  767. }
  768.  
  769.  
  770.  
  771. /********************/
  772. /*** Stereo Class ***/
  773. /********************/
  774.  
  775. SubbandLayer2Stereo::SubbandLayer2Stereo (uint32 subbandnumber)
  776. : SubbandLayer2 (subbandnumber)
  777. {
  778. }
  779.  
  780.  
  781. void SubbandLayer2Stereo::read_allocation (Ibitstream *stream, Header *header, Crc16 *crc)
  782. {
  783.   uint32 length = get_allocationlength (header);
  784.   allocation = stream->get_bits (length);
  785.   channel2_allocation = stream->get_bits (length);
  786.   if (crc)
  787.   {
  788.      crc->add_bits (allocation, length);
  789.      crc->add_bits (channel2_allocation, length);
  790.   }
  791. }
  792.  
  793.  
  794. void SubbandLayer2Stereo::read_scalefactor_selection (Ibitstream *stream, Crc16 *crc)
  795. {
  796.   if (allocation)
  797.   {
  798.      scfsi = stream->get_bits (2);
  799.      if (crc)
  800.         crc->add_bits (scfsi, 2);
  801.   }
  802.   if (channel2_allocation)
  803.   {
  804.      channel2_scfsi = stream->get_bits (2);
  805.      if (crc)
  806.         crc->add_bits (channel2_scfsi, 2);
  807.   }
  808. }
  809.  
  810.  
  811. void SubbandLayer2Stereo::read_scalefactor (Ibitstream *stream, Header *header)
  812. {
  813.   SubbandLayer2::read_scalefactor (stream, header);
  814.   if (channel2_allocation)
  815.   {
  816.      switch (channel2_scfsi)
  817.      {
  818.         case 0:
  819.     channel2_scalefactor1 = scalefactors[stream->get_bits (6)];
  820.     channel2_scalefactor2 = scalefactors[stream->get_bits (6)];
  821.     channel2_scalefactor3 = scalefactors[stream->get_bits (6)];
  822.     break;
  823.         case 1:
  824.     channel2_scalefactor1 = channel2_scalefactor2 = scalefactors[stream->get_bits (6)];
  825.     channel2_scalefactor3 = scalefactors[stream->get_bits (6)];
  826.     break;
  827.         case 2:
  828.     channel2_scalefactor1 = channel2_scalefactor2 =
  829.     channel2_scalefactor3 = scalefactors[stream->get_bits (6)];
  830.     break;
  831.         case 3:
  832.     channel2_scalefactor1 = scalefactors[stream->get_bits (6)];
  833.     channel2_scalefactor2 = channel2_scalefactor3 = scalefactors[stream->get_bits (6)];
  834.     break;
  835.      }
  836.      prepare_sample_reading (header, channel2_allocation, &channel2_groupingtable, &channel2_factor,
  837.                  &channel2_codelength, &channel2_c, &channel2_d);
  838.   }
  839. }
  840.  
  841.  
  842. BOOL SubbandLayer2Stereo::read_sampledata (Ibitstream *stream)
  843. {
  844.   BOOL returnvalue = SubbandLayer2::read_sampledata (stream);
  845.  
  846.   if (channel2_allocation)
  847.      if (channel2_groupingtable)
  848.      {
  849.         uint32 samplecode = stream->get_bits (channel2_codelength);
  850.         // create requantized samples:
  851.         samplecode += samplecode << 1;
  852.         register real *target = channel2_samples;
  853.         register const real *source = channel2_groupingtable + samplecode;
  854.         *target++ = *source++;
  855.         *target++ = *source++;
  856.         *target = *source;
  857.         // memcpy (channel2_samples, channel2_groupingtable + samplecode, 3 * sizeof (real));
  858.      }
  859.      else
  860.      {
  861.         channel2_samples[0] = real (stream->get_bits (channel2_codelength)) * channel2_factor - 1.0;
  862.         channel2_samples[1] = real (stream->get_bits (channel2_codelength)) * channel2_factor - 1.0;
  863.         channel2_samples[2] = real (stream->get_bits (channel2_codelength)) * channel2_factor - 1.0;
  864.      }
  865.   return(returnvalue);
  866. }
  867.  
  868.  
  869. BOOL SubbandLayer2Stereo::put_next_sample (e_channels channels,
  870.                         SynthesisFilter *filter1, SynthesisFilter *filter2)
  871. {
  872.   BOOL returnvalue = SubbandLayer2::put_next_sample (channels, filter1, filter2);
  873.   if (channel2_allocation && channels != left)
  874.   {
  875.      register real sample = channel2_samples[samplenumber - 1];
  876.  
  877.      if (!channel2_groupingtable)
  878.         sample = (sample + channel2_d) * channel2_c;
  879.  
  880.      if (groupnumber <= 4)
  881.         sample *= channel2_scalefactor1;
  882.      else if (groupnumber <= 8)
  883.         sample *= channel2_scalefactor2;
  884.      else
  885.         sample *= channel2_scalefactor3;
  886.      if (channels == both)
  887.         filter2->input_sample (sample, subbandnumber);
  888.      else
  889.         filter1->input_sample (sample, subbandnumber);
  890.   }
  891.   return(returnvalue);
  892. }
  893.  
  894.  
  895.